<?php

class ZFEngine_Form_Decorator_DivWrapper extends Default_Form_Decorator_ElementWrapperAbstract
{

    /**
     * Список элементов для обработки
     * @var array
     */
    protected $_elementsType = array(
        'Zend_Form_Element_Text',
        'Zend_Form_Element_Select',
    );

    /**
     * Render content wrapped in divs     
     *
     * @param string $content
     * @return string
     */
    public function render($content)
    {
        $elementName = $this->getElement()->getName();
        $elementId = $this->getElement()->getId();

        $label = $this->getElement()->getLabel();
        if( null === $label ) {
            $label = '&#160;';
        }

        $class = '';
        if (!is_null($this->getElement()->getAttrib('div-class'))) {
            $class = ' class="' . $this->getElement()->getAttrib('div-class') . '" ';
            $content = preg_replace('#div-class=".*?"#', '', $content);
        }

        return '<div id="' . $elementName . '-label" ' . $class . '><label for="' . $elementId . '">' . $label . '</label>' . $content . '</div>';
    }

}